//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lyq.bean.mySql;

import com.lyq.bean.JudgeSort;
import com.lyq.bean.User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class LoginSql {
    public LoginSql() {
    }

    public User login(String Usersort, String Username, String Pwd) {
        (new MysqlLinking()).getLink();
        Connection conn = MysqlLinking.conn;
        if (conn != null) {
            JudgeSort js = new JudgeSort(Usersort);
            String TableName = js.getTableName();
            String name = js.getUname();
            String password = js.getPwd();
            System.out.println(Usersort);
            try {
                String sql = "select * from " + TableName + " where " + name + "=? and " + password + "=?";
                PreparedStatement ps = conn.prepareStatement(sql);
                ps.setString(1, Username);
                ps.setString(2, Pwd);
                ResultSet rs = ps.executeQuery();
                String uname = "";

                String pwd;
                for(pwd = ""; rs.next(); pwd = rs.getString(password)) {
                    uname = rs.getString(name);
                }

                if (uname.equals(Username) && Pwd.equals(pwd)) {
                    User user = new User(uname, pwd);
                    return user;
                }
            } catch (Exception var15) {
                Exception e = var15;
                e.printStackTrace();
            }
        } else {
            System.out.println("数据库连接错误！");
        }

        return null;
    }
}
